package com.googlecode.allinclusive.fw.security;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * 用户信息
 * 
 * @author <a href="mailto:xiayg@cares.sh.cn">xiayg</a>
 * @version 1.0 2010-12-29
 */
public class User implements UserDetails {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 4397863263685020781L;
	/** 用户名*/
	private String username;
	/** 用户密码*/
	private String password;
	/** 用户授权*/
	private Collection<? extends GrantedAuthority> authorities;
	
	/**
	 * 设置用户名
	 * @param username 用户名
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * 设置用户密码
	 * @param password 用户密码
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * 设置用户授权
	 * @param authorities 用户授权
	 */
	public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
		this.authorities = authorities;
	}

	/**
	 * 返回用户授权
	 */
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	/**
	 * 返回用户密码
	 */
	@Override
	public String getPassword() {
		return password;
	}

	/**
	 * 返回用户名
	 */
	@Override
	public String getUsername() {
		return username;
	}

	/**
	 * 帐号是否过期
	 */
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	/**
	 * 帐号是否被锁
	 */
	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	/**
	 * 证书是否过期
	 */
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	/**
	 * 帐号是否有效
	 */
	@Override
	public boolean isEnabled() {
		return true;
	}
}
